import unittest
import utils
import requests

from api.login import LoginApi
from utils import DBUtil
from parameterized import parameterized


class TestReg(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.login_api = LoginApi()

    def setUp(self) -> None:
        self.session = requests.Session()
        # 数据清理
        sql1 = "DELETE FROM mb_member WHERE phone='13020210002';"
        sql2 = "DELETE FROM mb_member_info WHERE member_name='13020210002';"
        sql3 = "DELETE FROM mb_member_register_log WHERE member_name='13020210002';"
        DBUtil.execute(sql1, sql2, sql3)

    def tearDown(self) -> None:
        self.session.close()

    # 注册成功-必填参数
    @parameterized.expand(utils.build_data("reg.json"))
    def test01_reg(self, desc, phone, password, verifycode, phone_code, dy_server,invite_phone,
                   status_code, status, description):
        # 测试数据
        # phone = "13020210002"
        # password = "test123"
        # verifycode = "8888"
        # phone_code = "666666"
        # dy_server = "on"

        # 调用接口
        # 获取图片验证码
        r1 = self.login_api.get_img_verify_code(self.session, 0.111111)
        self.assertEqual(200, r1.status_code)
        # 获取短信验证码
        r2 = self.login_api.get_sms_code(self.session, phone, verifycode)
        print("get_sms_code data=", r2.json())
        utils.common_assert(self, r2, 200, 200, "短信发送成功")
        # 注册
        r3 = self.login_api.reg(self.session, phone, password, verifycode, phone_code, dy_server, invite_phone)
        print("reg data=", r3.json())

        # 断言
        utils.common_assert(self, r3, status_code, status, description)

    # # 注册成功-必填参数
    # def test01_reg_success(self):
    #     # 测试数据
    #     phone = "13020210002"
    #     password = "test123"
    #     verifycode = "8888"
    #     phone_code = "666666"
    #     dy_server = "on"
    #
    #     # 调用接口
    #     # 获取图片验证码
    #     r1 = self.login_api.get_img_verify_code(self.session, 0.111111)
    #     self.assertEqual(200, r1.status_code)
    #     # 获取短信验证码
    #     r2 = self.login_api.get_sms_code(self.session, phone, verifycode)
    #     print("get_sms_code data=", r2.json())
    #     utils.common_assert(self, r2, 200, 200, "短信发送成功")
    #     # 注册
    #     r3 = self.login_api.reg(self.session, phone, password, verifycode, phone_code, dy_server)
    #     print("reg data=", r3.json())
    #
    #     # 断言
    #     utils.common_assert(self, r3, 200, 200, "注册成功")
